var ASCaiNiao=function(){
    //游戏控制中心
	var game_control ={
		init:function(c){
			//初始化层
			layer_control.init(c);
            //资源加载模块
			GameLoadingModule.init();
			//声音初始
			//sound_control.init();
		}
	};
    //显示层控制中心
	var layer_control={
		init:function(c){
			this.background_layer=new cjs.Container();
			this.background_layer.parent=c;
			c.addChild(this.background_layer);
			
			this.active_layer=new cjs.Container();
			this.active_layer.parent=c;
			c.addChild(this.active_layer);
			
			this.ui_layer=new cjs.Container();
			this.ui_layer.parent=c;
			c.addChild(this.ui_layer);
			
			this.top_layer=new cjs.Container();
			this.top_layer.parent=c;
			c.addChild(this.top_layer);
		}
	};
	//消息中心
	var message_control={
		//消息模块
		dispatcher:new cjs.EventDispatcher(),
		//发送广播消息
		send:function(event){
			if(typeof(event)=='string'){
				this.dispatcher.dispatchEvent(new cjs.Event(event));
				return;
			}
			this.dispatcher.dispatchEvent(event);
		},
		//接收广播消息
		ceive:function(name,callback){
			this.dispatcher.addEventListener(name,callback);
		},
		//删除消息监听
		removeEvent:function(name,callback){
			this.dispatcher.removeEventListener(name,callback);
		}
	};
	//模块控制中心
	var module_control={
		init:function(){
            //游戏菜单模块
			MenuModule.init();
            //关卡过渡模块
            LevelModule.init();
		}
	};
    //GameLoadingModule模块
	var GameLoadingModule={
        init:function(){
            var layer=layer_control.active_layer;
            var view=new LoadingPageView();
			view.parent=layer;
			layer.addChild(view);
			this.view=view;

            var loader = new cjs.LoadQueue(true);
			loader.installPlugin(cjs.Sound);
			loader.addEventListener("fileload", function(evt){
                //console.log(evt.item);
				if (evt && (evt.item.type == "image")) { images[evt.item.id] = evt.result; }
			});
            loader.addEventListener("progress", function(evt){
				view.setProgress(parseInt(evt.progress*100));
			});
            loader.addEventListener("complete", function(evt){
                layer.removeChild(view);
				view.parent=null;
                //初始化模块
			    module_control.init();
                //发送模块事件,通知显示游戏菜单
                message_control.send(ModuleEvent.SHOW_MENU_SCREEN);
            });
            loader.loadManifest([
                {src:"./sounds/attack.mp3",id:"attack"},
                {src:"./sounds/bulletCrack.mp3",id:"bulletCrack"},
                {src:"./sounds/move.mp3",id:"move"},
                {src:"./sounds/playerCrack.mp3",id:"playerCrack"},
                {src:"./sounds/prop.mp3",id:"prop"},
                {src:"./sounds/start.mp3",id:"start"},
                {src:"./sounds/tankCrack.mp3",id:"tankCrack"},
                {src:"./images/menu.gif",id:"menu"},
                {src:"./images/tankAll.gif",id:"tankAll"}
            ]);
        }
    };
    //菜单模块
    var MenuModule={
        init:function(){
            var layer=layer_control.active_layer;
            var view=new MenuView();
            this.view=view;
            view.on(ViewEvent.GAME_START,function(){
				layer.removeChild(view);
				view.parent=null;
                //发送关卡过渡事件
                message_control.send(ModuleEvent.SHOW_LEVEL_SCREEN);
            },null,false);
            //接收显示游戏菜单事件
            message_control.ceive(ModuleEvent.SHOW_MENU_SCREEN,function(){
                view.parent=layer;
                layer.addChild(view);
                view.startMenuAnimate();
            });
        }
    };
    //关卡过渡模块
    var LevelModule={
        init:function(){
            var layer=layer_control.active_layer;
            var view=new LevelView();
            this.view=view;
			//
			view.on(ViewEvent.LEVEL_ANIMATE_COMPLETE,function(){
				layer.removeChild(view);
				view.parent=null;
				//
				GameModule.init();
			},null,false);
            //接收显示关卡过渡事件
            message_control.ceive(ModuleEvent.SHOW_LEVEL_SCREEN,function(){
                view.parent=layer;
                layer.addChild(view);
				view.startAnimate();
            });
        }
    };
	//游戏模块
	var GameModule={
		init:function(){
			var layer=layer_control.active_layer;
			var view=new GameView();
			this.view=view;
			view.parent=layer;
			layer.addChild(view);
		}
	};
	//
    this.properties={};
    this.GameControl=game_control;
	this.LayerControl=layer_control;
	//this.MessageControl=message_control;
	this.ModuleControl=module_control;
	//this.SoundControl=sound_control;
	//this.GameEvent=game_event;
};